<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>北京联合大学</title>
</head>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://at.alicdn.com/t/font_835526_xufba1hg66.css">
<link rel="stylesheet" href="../..//css/Initialization.css">
<link rel="stylesheet" href="../..//css/commen.css">
<link rel="stylesheet" href="../..//css/password.css">
<body>
<div id="content">
    <div class="initer">
        <!-- 具体内容 -->
        <div class="bread">
            <div class="plain">管理配置</div>
            <div class="plain">
                <i class="iconfont icon-right"></i>
            </div>
            <div class="plain current"><a href="classlist">班级设置管理</a></div>
            <div class="plain">
                <i class="iconfont icon-right"></i>
            </div>
            <div class="plain current">班级编辑</div>
        </div>
        <div class="modifypassword" style="margin-top: 50px;">
            <div class="modifyinput">
                <span class="text">学年名称</span>
                <input type="hidden" name="id" id="id" th:value="${depart.id}">
                <select name="pid" id="pid">
                    <option value="0">请选择</option>
                    <option th:each="item:${departs}" th:value="${item.id}" th:text="${item.departname}" th:selected="${item.id == depart.getPid()}"></option>
                </select>
            </div>
            <div class="modifyinput">
                <span class="text">班级名称</span>
                <input type="text" placeholder="请输入班级名称" name="departname" id="departname" th:value="${depart.departname}">
            </div>
            <div class="modifyinput">
                <span class="text">班级序号</span>
                <input type="text" placeholder="请输入班级序号" name="sort" id="sort" th:value="${depart.sort}">
            </div>
            <div class="modifyinput">
                <span class="center-button" id="subBut">保存</span>
                <span class="center-button" onclick="history.back()">返回</span>
            </div>
        </div>
    </div>
</div>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/commen.js"></script>
<script>
    $("#subBut").click(function(){
        var id = $("#id").val();
        var pid = $("#pid").val();
        var departname = $("#departname").val();
        var sort = $("#sort").val();

        if(pid == 0){
            alert("请选择学年");
            return false;
        }else if(departname.length == 0){
            $("#departname").focus();
            alert("请输入班级名称");
            return false;
        }else if(sort.length == 0){
            $("#sort").focus();
            alert("请输入班级序号");
            return false;
        }else{
            console.log(pid)
            $.ajax({
                type : "POST",
                url : "toadd",
                data : {id:id, pid: pid, departname: departname, sort:sort},
                dataType : "json",
                success : function(json) {
                    if(json.state == success){
                        alert("班级编辑成功");
                        location.href = "classlist";
                    }else{
                        alert("班级编辑失败");
                    }
                },
                error:function(msg){
                    alert("程序出错，请联系管理员");
                }
            });
        }
    });
</script>
</body>
</html>

